﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Mvc;
using MensUnoShop.Models;

namespace MensUnoShop.Helpers
{
    public static class OrderHtmlMarker
    {



        /// <summary>
        /// 取得訂單狀態
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="os"></param>
        /// <returns></returns>
        public static string GetOrderStatus(this HtmlHelper helper, Config.OrderStatusType ostype)
        {
            string returnStr = string.Empty;
            switch (ostype)
            {
                case Config.OrderStatusType.Init:
                case Config.OrderStatusType.Waiting:
                    returnStr = "未付款 Unpaid.";
                    break;
                case Config.OrderStatusType.Payment:
                    returnStr = "待出貨 Waiting for shipping.";
                    break;
                case Config.OrderStatusType.Fail:
                    returnStr = "交易失敗 Payment failed.";
                    break;
                case Config.OrderStatusType.Cannel:
                    returnStr = "訂單取消 Order canceled.";
                    break;
                case Config.OrderStatusType.Refunding:
                    returnStr = "待退款 Money-returned.";
                    break;
                case Config.OrderStatusType.Refunded:
                    returnStr = "已退款 Money-returned.";
                    break;
                case Config.OrderStatusType.ApplyReturn:
                    returnStr = "申請退貨 Apply to return.";
                    break;
                case Config.OrderStatusType.Shipping:
                    returnStr = "已出貨 Shipped.";
                    break;
                case Config.OrderStatusType.PreShipping:
                    returnStr = "出貨中 Shipping.";
                    break;
                default:
                    returnStr = "交易失敗 Payment failed";
                    break;
            }
            return returnStr;
        }

        public static string GetPayType(this HtmlHelper helper, PayType pt)
        {
            string result = string.Empty;
            switch (pt)
            {
                case PayType.Default:
                    result = "";
                    break;
                case PayType.CreditCard:
                    result = "信用卡";
                    break;
                case PayType.ATM:
                    result = "ATM";
                    break;
                case PayType.WebATM:
                    result = "WebATM";
                    break;
                case PayType.CS:
                    result = "超商代收";
                    break;
                case PayType.MMK:
                    result = "IBON / FamiPort / Life-ET";
                    break;
                case PayType.ALIPAY:
                    result = "支付寶";
                    break;
                default:
                    result = "其他";
                    break;
            }
            return result;
        }

        public static string GetShippingWay(this HtmlHelper helper, int? shippingway)
        {
            string returnStr = string.Empty;
            switch (shippingway)
            {
                case 0:
                    returnStr = "台灣地區免運費 (限時掛號、包裹)";
                    break;
                case 1:
                    returnStr = "亞洲Asia(EMS/國際快捷郵件)";
                    break;
                case 2:
                    returnStr = "美洲或歐洲America and Europe(EMS/國際快捷郵件)";
                    break;
                case 3:
                    returnStr = "中美洲或歐洲America and Europe(EMS/國際快捷郵件)";
                    break;
                default:
                    returnStr = "";
                    break;
            }
            return returnStr;
        }

        public static string GetInvoiceType(this HtmlHelper helper, int invoicetype)
        {
            string returnStr = string.Empty;
            switch (invoicetype)
            {
                case 0:
                    returnStr = "二聯式";
                    break;
                case 1:
                    returnStr = "三聯式";
                    break;
                default:
                    returnStr = "";
                    break;
            }
            return returnStr;
        }

        /// <summary>
        /// 使用生日折扣或coupon卷
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="isBirth">是否選擇生日折扣</param>
        /// <param name="hasBirth">是否可以選擇生日折扣</param>
        /// <param name="scck"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string GetBirthOrCoupon(this HtmlHelper helper, bool isBirth, bool hasBirth, string scck, MensUnoShop.Models.ITradeInDiscount id, int totalprice)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("");
            string _couponstring = "<tr><td colspan=\"6\"> <div align=\"right\" class=\"FONT_GREEN\" style=\"float:left\"><form action=\"\" method=\"post\" ><input type=\"hidden\" name=\"scck\" value=\"" + scck + "\" /><input type=\"hidden\" name=\"utype\" value=\"selcoupona\" />";
            _couponstring += "E-COUPON：<input name=\"ticket\" type=\"text\" id=\"ticket\" size=\"30\" class=\"MEMBER_BOX\" /><input type=\"submit\"  value=\"送出 Send\" />&nbsp;&nbsp;</form> </div><div style=\"float:right;text-align:left\"><span class=\"PRODUCT3_HOT_POINT couponnote\"></span></div></td>";
            string _birthstring = "<tr><td colspan=\"6\"> <div align=\"right\" class=\"FONT_GREEN\" style=\"float:left\"><form action=\"\" method=\"post\" >是否使用生日折扣？Do you want to use a 10% BIRTHDAY DISCOUNT?<input type=\"hidden\" name=\"scck\" value=\"" + scck + "\" /><input type=\"hidden\" name=\"utype\" value=\"selbirth\" />";
            _birthstring += "<input type=\"radio\" name=\"isbirth\" value=\"1\" onclick=\"this.form.submit();\" {0} />是&nbsp;&nbsp;<input type=\"radio\" name=\"isbirth\" value=\"0\" onclick=\"this.form.submit();\" {1} />否</form></div></td>";
            if(hasBirth &&isBirth)
                _birthstring = string.Format(_birthstring,"checked","");
            else
                _birthstring = string.Format(_birthstring,"","checked");

            
            int deprice = 0;
            if (id == null)
            {
                deprice = 0;
                if (hasBirth)
                {
                    sb.Append(_birthstring);
                    sb.Append("</td><td><div align=\"center\" class=\"FONT_GREEN\">NT$-" + deprice.ToString() + "</div></td>");
                    sb.Append(_couponstring);
                    sb.Append("</td><td><div align=\"center\" class=\"FONT_GREEN\">NT$-" + deprice.ToString() + "</div></td>");
                }
                else
                {
                    sb.Append(_couponstring);
                    sb.Append("</td><td><div align=\"center\" class=\"FONT_GREEN\">NT$-" + deprice.ToString() + "</div></td>");
                }
            }
            else
            {
                deprice = id.DEPRICE;
                if (id.SKTYPE == Config.OrderDiscountType.BirthDiscount)
                {
                    sb.Append(_birthstring);
                    sb.Append("</td><td><div align=\"center\" class=\"FONT_GREEN\">NT$-" + deprice.ToString() + "</div></td>");
                }
                else
                {
                    if (hasBirth)
                    {
                        sb.Append(_birthstring);
                        sb.Append("</td><td><div align=\"center\" class=\"FONT_GREEN\">NT$-0</div></td>");

                        sb.Append(_couponstring);
                        sb.Append("</td><td><div align=\"center\" class=\"FONT_GREEN\">NT$-" + deprice.ToString() + "</div></td>");
                    }
                    else
                    {
                        sb.Append(_couponstring);
                        sb.Append("</td><td><div align=\"center\" class=\"FONT_GREEN\">NT$-" + deprice.ToString() + "</div></td>");
                    }
                }
            }

            return sb.ToString();
        }

    }
}